package com.zmn.oms.common.constant;

import com.alibaba.fastjson.JSON;
import com.zmn.oms.common.utils.HttpUtil;
import com.zmn.tapi.common.export.model.dio.ExportHttpDIO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 类描述：订单导出常量
 *
 * @author wangxiaokun
 * @since 2021/08/17 11:05
 */
@Slf4j
@Component
public class OrderExportConsts {

    // tapi导出服务地址
    private static String ZMN_TAPI_EXPORT_URL;

    @Value("${zmn.tapi.export.url:http://test2-tapi.xiujiadian.com/api/export/exportMultipleSheetInfo}")
    public void setZmnTapiExportUrl(String zmnTapiExportUrl) {
        ZMN_TAPI_EXPORT_URL = zmnTapiExportUrl;
    }

    /**
     * 支付明细导出
     */
    public static final int EXPORT_TYPE_ORDER_PAY_LIST = 1; // 收款汇总导出
    public static final int EXPORT_TYPE_ORDER_PAY_REFUND_LIST = 2; // 退款汇总导出
    public static final int EXPORT_TYPE_ORDER_PAY_DETAIL_LIST = 3; // 收付明细导出

    /**
     * 异步导出请求
     * @param exportHttpDIO
     */
    public static void exportHttps(ExportHttpDIO exportHttpDIO) {
        try {
            String response = HttpUtil.httpsPost(ZMN_TAPI_EXPORT_URL, JSON.toJSONString(exportHttpDIO));
            log.info("异步导出出参，taskId={}，【{}】", exportHttpDIO.getExportTaskId(), response);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("异步导出失败：taskId=【{}】失败信息：【{}】", exportHttpDIO.getExportTaskId(), e.getMessage());
        }
    }
}
